package com.example.controller;

import com.example.dto.StudentDetailDTO;
import com.example.pojo.PageBean;
import com.example.pojo.Result;
import com.example.pojo.Student;
import com.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;

    // 获取学生列表（支持分页和姓名模糊查询）
    @GetMapping
    public Result<PageBean<Student>> list(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(required = false) String name) {
        PageBean<Student> pb = studentService.list(pageNum, pageSize, name);
        return Result.success(pb);
    }

    @GetMapping("/detail")
    public Result<StudentDetailDTO> getStudentDetail(@RequestParam Integer id) {
        StudentDetailDTO detail = studentService.getStudentDetail(id);
        return Result.success(detail);
    }

    // 增加学生信誉分
    @PostMapping("/increaseCreditScore")
    public Result increaseCreditScore(@RequestParam Integer id, @RequestParam int points) {
        studentService.increaseStudentCreditScore(id, points);
        return Result.success();
    }

    // 减少学生信誉分
    @PostMapping("/decreaseCreditScore")
    public Result decreaseCreditScore(@RequestParam Integer id, @RequestParam int points) {
        studentService.decreaseStudentCreditScore(id, points);
        return Result.success();
    }
}